home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 20 / tvxsrc / tvx_unix.c < prev   
Encoding:
C/C++ Source or Header  |  1987-07-19  |  17.8 KB  |  779 lines

  1. /* -------------------------- tvx_unix.c ------------------------------ */
  2. #include "tvx_defs.ic"
  3. #include "tvx_glbl.ic"
  4.  
  5. #ifdef SYSV
  6. #undef VQUIT            /* name conflict with sys V - irrelevant
  7.                 name in tvx_unix.c */
  8. #include <termio.h>
  9. #endif
  10.  
  11. #define TEMPEXT ".t1"        /* temporary file */
  12. #define BACKEXT ".B"        /* backup file */
  13. #define SWITCH '-'
  14. #define FILESEP '.'
  15.  
  16. /* define USETMP if you want intermediate workfiles built on
  17.    /tmp.  Otherwise, they will be built on the same directory as
  18.    the original file.  This latter method is often a bit faster,
  19.    especially when exiting if /tmp is on a different volume than
  20.    the destination file (which makes mv COPY the file rather than
  21.    just renameing. */
  22.  
  23. #define USETMP             /* define if create temp files on /tmp */
  24.  
  25. #include <ctype.h>
  26. #include <sys/ioctl.h>
  27.  
  28. #include <sys/types.h>
  29.  
  30. #ifdef ULTRIX11
  31. #include <sgtty.h>
  32. #endif
  33.  
  34. #ifdef SCR_BUF
  35. char *Scrbuf;                   /* Base address of screen buffer. */
  36. char *Scrptr;                   /* Dynamic screen buffer pointer. */
  37. #endif
  38. /* --------------  terminal I/O stuff --------------- */
  39.  
  40. #ifdef SYSV
  41. static struct termio sgb;
  42. #else
  43. static struct sgttyb sgb;
  44. static struct tchars tch;
  45. static struct ltchars ltc;
  46. #endif
  47.  
  48. #define Ioctl ioctl
  49. #define Read read
  50. #define Write write
  51.  
  52. /* ------------- file mode stuff ---------------------- */
  53. #include <sys/stat.h>
  54.   static struct stat info;        /* structure to get info */
  55.  
  56. /* ------------- misc stuff ---------------------- */
  57.  
  58.   extern int errno;
  59.   extern char **environ;
  60.  
  61.  
  62. #ifdef TERMCAP            /* routines needed for termcap */
  63. /* ------------- termcap stuff ---------------------- */
  64.   char PC;
  65.   char *BC;
  66.   char *UP;
  67.   char TERM[40];
  68.   short ospeed;
  69.  
  70.   static char Tcm[80];        /* special entry for cm */
  71.   static char empty[2];
  72.   static char Tbc[20];
  73.   static char Tup[20];
  74.  
  75.   static int    Tco,            /* number of columns per line */
  76.         Tli;            /* number of lines */
  77.  
  78.   static char tcbuff[1024];        /* buffer to hold termcap entry */
  79.  
  80.  
  81. /* ==========================>>> gettermcap  <<<========================= */
  82.   gettermcap()
  83.   {
  84.     char *tp;
  85.     char *getenv();
  86.     char entry[80];        /* scratch buffer for entry */
  87.  
  88.     empty[0] = 0;
  89.  
  90. #ifdef SYSV
  91.     ospeed = sgb.c_cflag & CBAUD;
  92. #else
  93.     ospeed = sgb.sg_ospeed;    /* get the speed */
  94. #endif
  95.  
  96.     if ((tp = getenv("TERM")) == NULL)
  97.       {
  98.     goto FORCETTY;
  99.       }
  100.     strcpy(TERM,tp);        /* copy to our TERM */
  101.  
  102.     if (tgetent(tcbuff,TERM) < 1)
  103.       {
  104.     goto FORCETTY;
  105.       }
  106.  
  107. /*    read required termcap entries, save in appropriate TVX arrays */
  108.  
  109.     if (!gettcap("cm",Tcm))
  110.       {
  111.     goto FORCETTY;
  112.       }
  113.  
  114.     if (!gettcap("ce",entry))
  115.       {
  116.     goto FORCETTY;
  117.       }
  118.     if (!capcpy(celin,entry,7))    /* copy entry to end of line */
  119.       {
  120.     goto FORCETTY;
  121.       }
  122.     
  123.     if (tgetflag("da"))
  124.     dsp_mem = TRUE;            /* display has memory */
  125.     else if (tgetflag("db"))
  126.     dsp_mem = TRUE;
  127.  
  128.     gettcap("cd",entry);        /* clear to end of display */
  129.     capcpy(cescr,entry,7);
  130.  
  131.     gettcap("al",entry);        /* insert a line (add line) */
  132.     capcpy(ciline,entry,7);
  133.  
  134.     gettcap("dl",entry);    /* delete a line */
  135.     capcpy(ckline,entry,7);
  136.  
  137.     if (!gettcap("sr",entry))    /* reverse scroll */
  138.       {
  139.     strcpy(ctopb,ciline);    /* add line works the same */
  140.       }
  141.     else
  142.     capcpy(ctopb,entry,7);
  143.  
  144.     gettcap("dc",entry);        /* delete character */
  145.     capcpy(cdelchr,entry,7);
  146.     gettcap("cl",entry);        /* clear screen */
  147.     capcpy(cclears,entry,7);
  148.  
  149.  
  150.     gettcap("ve",entry);        /* stand cursor changer end */
  151.     capcpy(ccsrcm,entry,7);
  152.     gettcap("vs",entry);        /* stand cursor changer begin */
  153.     capcpy(ccsrin,entry,7);
  154.  
  155.     gettcap("se",entry);        /* stand out end */
  156.     capcpy(cbolde,entry,7);
  157.  
  158.     gettcap("so",entry);        /* begin standout */
  159.     capcpy(cboldb,entry,7);
  160.  
  161.     cerred[0] = 7;                /* bell for sure */
  162.     gettcap("vb",entry);        /* visual bell? */
  163.     if (*entry)
  164.     capcpy(cerred,entry,7);
  165.  
  166.     if (!capcpy(&cversn[1],TERM,10))        /* copy name to version */
  167.     strcpy(cversn,"TERMCAP");
  168.  
  169.     if ((Tco = tgetnum("co")) < 0)    /* # of cols */
  170.     Tco = 79;        /* assume 80 x 24 */
  171.     if ((Tli = tgetnum("li")) < 0)    /* # of lines */
  172.     Tli = 24;        /* assume 80 x 24 */
  173.  
  174.     tvhardlines = tvlins = Tli;    /* number of lines */
  175.     tvcols = Tco - 1; /* set col val (-1 avoids all the line wrap crap )*/
  176.     if (tvhardlines != 24 || tvhardlines != 25)    /* strange terminal */
  177.       {
  178.     ddline = (tvlins / 2) + 1;
  179.     setdscrl();        /* calculate scroll */
  180.       }
  181.  
  182.     gettcap("bc",entry);        /* get backspace character */
  183.     if (!*entry)
  184.       {
  185.     Tbc[0] = 8; Tbc[1] = 0;
  186.       }
  187.     else
  188.     capcpy(Tbc,entry,19);
  189.     BC = Tbc;
  190.     gettcap("up",entry);        /* get backspace character */
  191.     if (!*entry)
  192.       {
  193.     Tup[0] = 0;
  194.       }
  195.     else
  196.     capcpy(Tup,entry,19);
  197.     UP = Tup;
  198.     gettcap("pc",entry);        /* get the pad character */
  199.     PC = *entry;
  200.  
  201. #ifdef USE_TC_is
  202.     gettcap("is",entry);        /* initialization string */
  203.     tcapcs(entry);            /* send the intialization string */
  204. #endif
  205.  
  206.     gettcap("ti",entry);        /* cm initialization string */
  207.     tcapcs(entry);            /* send the intialization string */
  208.  
  209.     return;
  210.  
  211. FORCETTY:
  212.    reset();
  213.    remark("");
  214.    remark("Unable to set up for video terminal.");
  215.    exit(999);
  216.   }
  217.  
  218. /* =============================>>> capcpy  <<<============================= */
  219.   capcpy(to,from,len)
  220.   char *to, *from;
  221.   int len;
  222.   {        /* copy a capability, checking length */
  223.     if (strlen(from) > len)
  224.       {
  225.     *to = 0;
  226.     return (FALSE);
  227.       }
  228.     else
  229.     strcpy(to,from);
  230.     return (TRUE);
  231.   }
  232.  
  233. /* =============================>>> gettcap  <<<============================= */
  234.   gettcap(cap,area)
  235.   char *cap, *area;
  236.   {
  237.     char **cpp, *cp;
  238.  
  239.     cpp = &cp;        /* I think */
  240.     cp = area;
  241.     *area = 0;        /* assume null entry */
  242.  
  243.     tgetstr(cap,cpp);    /* get the capability */
  244.     return (*area);        /* return 1st char */
  245.     
  246.   }
  247.  
  248. /* =============================>>> tcapcs  <<<============================= */
  249.   tcapcs(str)
  250.   char *str;
  251.   {
  252.      /* send a termcap generated control string to terminal */
  253.  
  254.     register char *cp;
  255.     int ttwt();
  256.  
  257.     if (!(echof && !bakflg))
  258.     return;
  259.     if (!*str)        /* don't send null strings */
  260.     return;
  261.     cp = str;
  262.     tputs(cp,1,ttwt);
  263.  
  264.   }
  265.  
  266. /* =============================>>> tcapxy  <<<============================= */
  267.   tcapxy(x,y)
  268.   int x,y;
  269.   {
  270.     /* move cursor to x,y */
  271.  
  272.    char *tgoto();
  273.  
  274.    tcapcs(tgoto(Tcm,x-1,y-1));    /* send the string, adjusting x,y */
  275.  
  276.   }
  277. #endif   /* termcap */
  278.  
  279.  
  280. /* =============================>>> ttinit  <<<============================= */
  281.   ttinit()
  282.   {
  283. #ifdef SYSV
  284.     struct termio nsgb;
  285. #else
  286.     struct sgttyb nsgb;
  287.     struct tchars ntch;
  288.     struct ltchars nltc;
  289. #endif
  290.  
  291. #ifdef SCR_BUF
  292.     char *malloc();
  293.  
  294.     /* malloc the screen buffer */
  295.     if ((Scrbuf = malloc(S_BUFSIZE)) == NULL)
  296.       {
  297.     reset();
  298.     remark("");
  299.     remark("tvx: cannot allocate screen buffer, aborting");
  300.     exit(999);
  301.       }
  302.     Scrptr = Scrbuf;
  303. #endif
  304.  
  305. #ifdef SYSV
  306.     (void) Ioctl(0, TCGETA, &sgb);
  307.     (void) Ioctl(0, TCGETA, &nsgb);
  308. #else
  309.     (void) Ioctl(0, TIOCGETP, &sgb);
  310.     (void) Ioctl(0, TIOCGETP, &nsgb);
  311.     (void) Ioctl(0, TIOCGETC, &tch);
  312.     (void) Ioctl(0, TIOCGETC, &ntch);
  313.     (void) Ioctl(0, TIOCGLTC, <c);
  314. #endif
  315.  
  316. #ifdef SYSV
  317.     nsgb.c_lflag &= ~(ECHO | ICANON | ISIG);    /* ISIG added 7/9/86 bew */
  318.     nsgb.c_iflag &= ~(ICRNL | IXOFF);
  319. #else
  320.     nsgb.sg_flags |= CBREAK;
  321.     nsgb.sg_flags &= ~(CRMOD|ECHO|LCASE|TANDEM);
  322. #endif
  323.  
  324. #ifdef SYSV
  325.     nsgb.c_cc[VMIN] = 1;    /* minimum characters */
  326.     nsgb.c_cc[VTIME] = -1;    /* time before read returns */
  327. #else
  328.     ntch.t_intrc = -1;  /* interrupt */
  329.     ntch.t_quitc = -1;  /* quit */
  330.     ntch.t_eofc = -1;   /* end-of-file */
  331.     ntch.t_brkc = -1;   /* input delimiter (like nl) */
  332. #endif
  333.  
  334. /* the following two lines control flow control */
  335.  
  336. #ifndef FLOWCONTROL
  337. #ifdef SYSV
  338.     nsgb.c_iflag &= ~(IXON | IXOFF);
  339. #else
  340.     ntch.t_startc = -1; /* start output */
  341.     ntch.t_stopc = -1;  /* stop output */
  342. #endif
  343. #endif
  344.  
  345. #ifndef SYSV
  346.     nltc.t_suspc = -1;  /* stop process signal */
  347.     nltc.t_dsuspc = -1; /* delayed stop process signal */
  348.     nltc.t_rprntc = -1; /* reprint line */
  349.     nltc.t_flushc = -1; /* flush output (toggles) */
  350.     nltc.t_werasc = -1; /* word erase */
  351.     nltc.t_lnextc = -1; /* literal next character */
  352. #endif
  353.  
  354. #ifdef SYSV
  355.     (void) Ioctl(0, TCSETA, &nsgb);
  356. #else
  357.     (void) Ioctl(0, TIOCSETP, &nsgb);
  358.     (void) Ioctl(0, TIOCSETC, &ntch);
  359.     (void) Ioctl(0, TIOCSLTC, &nltc);
  360. #endif
  361.  
  362. #ifdef TERMCAP
  363.     gettermcap();            /* set up terminal characteristics */
  364. #endif
  365.  
  366.     info.st_mode = -1;            /* no mode stuff yet */
  367.  }
  368.  
  369.  
  370. #ifdef SCR_BUF
  371. /* =============================>>> ttflush  <<<============================= */
  372.   ttflush()
  373.   {
  374.     if (Scrptr != Scrbuf)
  375.     write(1, Scrbuf, (unsigned) (Scrptr - Scrbuf));
  376.     Scrptr = Scrbuf;
  377.   }
  378. #endif
  379.  
  380. /* =============================>>> ttrd_unix  <<<============================= */
  381.   ttrd_unix()
  382.   {
  383.            char c;
  384.  
  385.     Read(0, &c, 1);
  386.     return(c);
  387.   }
  388.  
  389. /* =============================>>> ttwtln  <<<============================= */
  390.   ttwtln(cbuf,cnt)
  391.   char *cbuf;
  392.   int cnt;
  393.   {
  394. #ifndef SCR_BUF
  395.     if (echof && !bakflg)
  396.     Write(1, cbuf, cnt);
  397. #else
  398.     if (echof && !bakflg)
  399.       {
  400.     while(cnt-- > 0)
  401.       {
  402.             if (Scrptr < Scrbuf + S_BUFSIZE)
  403.                 *Scrptr++ = *cbuf++;
  404.             else
  405.           {
  406.                 ttflush();
  407.                 *Scrptr++ = *cbuf++;
  408.           }
  409.       }
  410.       }
  411. #endif
  412.   }
  413.  
  414. /* =============================>>> ttwt  <<<============================= */
  415.   ttwt(c)
  416.   char c;
  417.   {
  418. #ifndef SCR_BUF
  419.     Write(1, &c, 1);
  420. #else
  421.     if (Scrptr < Scrbuf + S_BUFSIZE)
  422.         *Scrptr++ = c;
  423.     else
  424.       {
  425.         ttflush();
  426.         *Scrptr++ = c;
  427.       }
  428. #endif
  429.   }
  430.  
  431. /* =============================>>> ttclos  <<<============================= */
  432.   ttclos()
  433.   {
  434.  
  435. #ifdef TERMCAP
  436.     char entry[80];
  437.  
  438.     gettcap("te",entry);        /* cm end up string */
  439.     tcapcs(entry);            /* send it */
  440. #endif
  441.  
  442. #ifdef SYSV
  443.     (void) Ioctl(0, TCSETA, &sgb);
  444. #else
  445.     (void) Ioctl(0, TIOCSETP, &sgb);
  446.     (void) Ioctl(0, TIOCSETC, &tch);
  447.     (void) Ioctl(0, TIOCSLTC, <c);
  448. #endif
  449.   }
  450.  
  451. /* =============================>>> ttosinit  <<<============================= */
  452.   ttosinit()
  453.   {            /* need a special version for not doing termcap */
  454. #ifdef SYSV
  455.     struct termio nsgb;
  456. #else
  457.     struct sgttyb nsgb;
  458.     struct tchars ntch;
  459.     struct ltchars nltc;
  460. #endif
  461.  
  462.     char entry[80];        /* scratch buffer for entry */
  463.  
  464. #ifdef SYSV
  465.     (void) Ioctl(0, TCGETA, &sgb);
  466.     (void) Ioctl(0, TCGETA, &nsgb);
  467. #else
  468.     (void) Ioctl(0, TIOCGETP, &sgb);
  469.     (void) Ioctl(0, TIOCGETP, &nsgb);
  470.     (void) Ioctl(0, TIOCGETC, &tch);
  471.     (void) Ioctl(0, TIOCGETC, &ntch);
  472.     (void) Ioctl(0, TIOCGLTC, <c);
  473. #endif
  474.  
  475. #ifdef SYSV
  476.     nsgb.c_lflag &= ~(ECHO | ICANON);
  477.     nsgb.c_iflag &= ~(ICRNL | IXOFF);
  478. #else
  479.     nsgb.sg_flags |= CBREAK;
  480.     nsgb.sg_flags &= ~(CRMOD|ECHO|LCASE|TANDEM);
  481. #endif
  482.  
  483. #ifdef SYSV
  484.     nsgb.c_cc[VMIN] = 1;    /* minimum characters */
  485.     nsgb.c_cc[VTIME] = -1;    /* time before read returns */
  486. #else
  487.     ntch.t_intrc = -1;  /* interrupt */
  488.     ntch.t_quitc = -1;  /* quit */
  489.     ntch.t_eofc = -1;   /* end-of-file */
  490.     ntch.t_brkc = -1;   /* input delimiter (like nl) */
  491. #endif
  492.  
  493. /* the following two lines control flow control */
  494.  
  495. #ifndef FLOWCONTROL
  496. #ifdef SYSV
  497.     nsgb.c_iflag &= ~(IXON | IXOFF);
  498. #else
  499.     ntch.t_startc = -1; /* start output */
  500.     ntch.t_stopc = -1;  /* stop output */
  501. #endif
  502. #endif
  503.  
  504. #ifndef SYSV
  505.     nltc.t_suspc = -1;  /* stop process signal */
  506.     nltc.t_dsuspc = -1; /* delayed stop process signal */
  507.     nltc.t_rprntc = -1; /* reprint line */
  508.     nltc.t_flushc = -1; /* flush output (toggles) */
  509.     nltc.t_werasc = -1; /* word erase */
  510.     nltc.t_lnextc = -1; /* literal next character */
  511. #endif
  512.  
  513. #ifdef SYSV
  514.     (void) Ioctl(0, TCSETA, &nsgb);
  515. #else
  516.     (void) Ioctl(0, TIOCSETP, &nsgb);
  517.     (void) Ioctl(0, TIOCSETC, &ntch);
  518.     (void) Ioctl(0, TIOCSLTC, &nltc);
  519. #endif
  520.  
  521. #ifdef TERMCAP
  522. #ifdef USE_TC_is
  523.     gettcap("is",entry);        /* initialization string */
  524.     tcapcs(entry);            /* send the intialization string */
  525. #endif
  526.  
  527.     gettcap("ti",entry);        /* cm initialization string */
  528.     tcapcs(entry);            /* send the intialization string */
  529. #endif
  530.  }
  531.  
  532. /* ==========================>>> unix_sys  <<<============================= */
  533.   unix_sys()
  534.   {
  535.     char rp[150];
  536.  
  537.     tvclr();            /* clear the screen */
  538. DO_UNIX:
  539.     remark("Unix command interface"); remark("");
  540.     remark("Enter Unix command line: ");
  541.     reply(rp,149);
  542.     reset();        /* reset terminal to unix mode */
  543.  
  544.     system(rp);
  545.  
  546.     ttosinit();        /* reset terinal to our mode */
  547.  
  548.     remark("");
  549.     remark("");
  550.  
  551.     prompt("Any key to continue with edit (! for another Unix command): ");
  552.     reply(rp,1);
  553.  
  554.     trmini();        /* this has to be here or screen is cleared! */
  555.     if (*rp == '!')
  556.     goto DO_UNIX;
  557.  
  558.     verify(1);
  559.   }
  560.  
  561. /* =============================>>> get_mode <<<============================= */
  562.   get_mode(f)
  563.   FILE *f;
  564.   {        /* gets access mode of open file f */
  565.  
  566.     char rp[10];
  567.  
  568.     info.st_mode = -1;    /* assume no mode */
  569.  
  570.     if (newfil)
  571.     return;
  572.     if (fstat(fileno(f),&info) != 0)
  573.       {
  574.     info.st_mode = -1;    /* assume no mode */
  575.     return;
  576.       }
  577.     info.st_mode &= 07777;    /* zap extraneous stuff*/
  578.     if (((info.st_mode & 0222) == 0) || rdonly)    /* no write permission */
  579.       {
  580.     prompt("No write permission for file, edit R/O? (y/n) ");
  581.     ureply(rp,1);
  582.     if (*rp == 'Y')
  583.         rdonly = TRUE;
  584.     else
  585.       {
  586.         reset();
  587.         exit(999);
  588.       }
  589.       }
  590.   }
  591.  
  592. #ifdef SYSV
  593. /* =============================>>> set_mode <<<============================= */
  594.   set_mode(fname)
  595.   char *fname;
  596.   {        /* sets access mode of open file f */
  597.     if (newfil || info.st_mode == -1)
  598.     return;
  599.  
  600.     if (chmod(fname,info.st_mode) != 0)
  601.     tverrb("Unable to set file mode, umask will be used.");
  602.   }
  603.  
  604. #else
  605. /* =============================>>> set_mode <<<============================= */
  606.   set_mode(f)
  607.   FILE *f;
  608.   {        /* sets access mode of open file f */
  609.     if (newfil || info.st_mode == -1)
  610.     return;
  611. #ifndef ULTRIX11
  612.     if (fchmod(fileno(f),info.st_mode) != 0)
  613. #endif
  614.     tverrb("Unable to set file mode, umask will be used.");
  615.   }
  616. #endif
  617.  
  618. /* ==========================>>> expand_name <<<============================ */
  619.   expand_name(n)
  620.   char *n;
  621.   {        /* expands unix file names */
  622.     char tmp[FNAMESIZE+1];
  623.  
  624.     if ((*n == '~') && (n[1] == '/'))
  625.       {
  626.     strcpy(tmp,getenv("HOME"));
  627.     scopy(n,1,tmp,strlen(tmp));
  628.     strcpy(n,tmp);
  629.       }
  630.   }
  631.  
  632. /* =============================>>> ren_file <<<=========================== */
  633.   ren_file(old,new)
  634.   char *old, *new;
  635.   {
  636.     int pid;
  637.     static char *mvarg[4];
  638.     static int status;
  639.  
  640.     if (rename(old,new) != 0)
  641.       {
  642.     mvarg[0] = "/bin/mv";
  643.     mvarg[1] = old;
  644.     mvarg[2] = new;
  645.     mvarg[3]=0;
  646.     pid = fork();
  647.     if (pid == 0)
  648.       {
  649.         execve("/bin/mv",mvarg,environ);
  650.             tverrb("Error trying to start mv utility");
  651.         _exit(999);
  652.       }
  653.     wait(&status);
  654.     if (status > 255)        /* error return */
  655.       {
  656.         prompt(old) ; prompt(" not renamed to "); remark(new);
  657.         prompt("Edited file found as: "); remark(old);
  658.       }
  659.       }
  660.   }
  661.  
  662. /* =============================>>> temp_name <<<=========================== */
  663.   temp_name(n,first)
  664.   char *n;
  665.   int first;
  666.   {
  667.     /* generates a temporary name from n.  Depending on value of
  668.        first, it will either add a 1 or 2 to name */
  669.     SLOW int i;
  670.  
  671. #ifdef USETMP
  672.     SLOW char pidno[20];
  673. #ifdef XENIX286
  674.     int pidint;
  675. #else
  676.     long pidint;
  677. #endif
  678.  
  679.     if (first)            /* create full temp name */
  680.       {
  681.     *n = 0;
  682.     pidint = getpid();
  683.     tvitoa(pidint,pidno);
  684.     strcpy(n,"/tmp/tvx1");
  685.     scopy(pidno,0,n,9);
  686.       }
  687.     else            /* alternate between 1 and 2 */
  688.       {
  689.     if (n[8] == '1')
  690.         n[8] = '2';
  691.     else
  692.         n[8] = '1';
  693.       }
  694. #else
  695.     if (first)
  696.       {
  697.     if ((i = rindx(n,FILESEP)) > 0)    /* see if extenstion */
  698.         scopy(TEMPEXT,0,n,i);        /* make .bak */
  699.     else
  700.       {
  701.         scopy(TEMPEXT,0,n,strlen(n));    /* just add on */
  702.       }
  703.       }
  704.     else
  705.       {
  706.     i = strlen(n);
  707.     if (n[i-1] == '1')
  708.         n[i-1] = '2';
  709.     else
  710.         n[i-1] = '1';
  711.       }
  712. #endif
  713.   }
  714.  
  715. #ifndef SUN
  716. /* =============================>>> USER_1 <<<============================= */
  717.   user_1(knt)
  718.   int knt;
  719.   {
  720.     knt = 0;
  721.     return (TRUE);
  722.   }
  723.  
  724. #else
  725. /* =============================>>> USER_1 <<<============================= */
  726.   user_1(knt)
  727.   int knt;
  728.   {
  729.     /* for suns, re-initialize window */
  730. #ifdef TERMCAP
  731.     gettermcap();        /* set up terminal characteristics */
  732.     tvidefs();        /* and reset defs */
  733. #endif
  734.     verify(1);
  735.     return (TRUE);
  736.   }
  737. #endif
  738.  
  739. /* =============================>>> USER_2 <<<============================= */
  740.   user_2(knt)
  741.   int knt;
  742.   {
  743.     knt = 0;
  744.     return (TRUE);
  745.   }
  746.  
  747. #ifdef SYSV
  748. /* ============================>>> RENAME <<<============================ */
  749.   rename(from, to)
  750.   char *from, *to;
  751.   {
  752.     /* SYSV rename code repaired 7/9/86 - BEW */
  753.     if (access(from,00) != 0)        /* from must exit */
  754.     return (-1);
  755.     if (access(to,00) == 0)        /* to must not exist */
  756.     unlink(to);
  757.     if (link(from,to) != 0)        /* link old to new name */
  758.     return (-1);
  759.     return (unlink(from));        /* and unlink the old name */
  760.   }
  761. #endif
  762.  
  763. #ifdef PRO350
  764. /* =============================>>> rename <<<============================= */
  765.   rename(old, new)
  766.   char *old;
  767.   char *new;
  768.   {
  769.     int res;
  770.  
  771.     if ((res = link(old, new)) < 0)
  772.     return (res);
  773.     else
  774.     unlink(old);
  775.     return (0);
  776.   }
  777. #endif
  778. /* -------------------------- tvx_unix.c ------------------------------ */
  779. ə